var validatFn = {
	numberReg:/^\d+$/,
	dateReg:/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/,
	textVal : function(o){
	
	},
	ckNull  : function(o){
		o = o||"";
		return (o.value == "" || o.value.trim() == "" || o.value == "undefined");
	},
	ckNumber:function(o){
		return validatFn.numberReg.test(o.value);	
	},
	ckFileType:function(o,ts){
		var file = o.value;
		var files = file.split(".");
		try{
			var type = files[files.length-1];
			if($.isArray(ts)){
				var d = false;
				for(var i = 0 ; i<ts.length ; i++){
					if(ts[i] == type)d=true;
				}
				return d;
			}else{
				return type == ts;
			}
			
		}catch(e){ alert(e);	}
		return false;
	}
}

$(document).ready(function(){

	$(".text > input").blur(function(e){
		var isNull = $(this).attr("null");
		var msgBox = $(this).parent().find(".crudHelp");
		
		if(isNull){
			if(validatFn.ckNull(this)){
				msgBox.text("填写不能为空!");
				msgBox.css("color","red");
			}else{
				msgBox.text("填写满足要求");
				msgBox.css("color","#437EBA");
			}
		}
	});
	
	$(".number > input").blur(function(e){
		var isNull = $(this).attr("null");
		var msgBox = $(this).parent().find(".crudHelp");
		
		if(isNull){
			if(validatFn.ckNull(this)){
				msgBox.text("填写不能为空!");
				msgBox.css("color","red");
				return;
			}
		}
		if(!validatFn.ckNumber(this)){
			msgBox.text("请填写数值类型!");
			msgBox.css("color","red");
		}else{
			msgBox.text("填写满足要求");
			msgBox.css("color","#437EBA");
		}
		
	});
	
	$(".image_file > input").blur(function(e){
		var isNull = $(this).attr("null");
		var msgBox = $(this).parent().find(".crudHelp");
		if(!validatFn.ckFileType(this,new Array("gif","png","jpg","jpeg"))){
			msgBox.text("请选择文件格式为jpg,jpeg,png,gif的图片文件");
			msgBox.css("color","red");
		}else{
			msgBox.text("填写满足要求");
			msgBox.css("color","#437EBA");
		}
	});
	
	$(".data > input").blur(function(e){
		var isNull = $(this).attr("null");
		var msgBox = $(this).parent().find(".crudHelp");
		
		if(isNull){
			if(validatFn.ckNull(this)){
				msgBox.text("填写不能为空!");
				msgBox.css("color","red");
			}
		}else{
			msgBox.text("填写满足要求");
			msgBox.css("color","#437EBA");
		}
	});

});